package com.bnz.rabbit.demo1;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @author xy
 * @date 2022/10/26
 */
public class ProducerClient {
    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception{
        //连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("120.48.117.8");
        factory.setUsername("baizhi");
        factory.setPassword("123456!");
        //创建信道
        try(Connection connection = factory.newConnection();
            Channel channel =connection.createChannel()){
            String message = "bai zhi first message";
            /**
             * 1.列队名称
             * 2.消息是否持久化
             * 3.该列队是否可以多次消费
             * 4.是否自动删除
             * 5.
             */
            channel.queueDeclare(QUEUE_NAME,false,false,false,null);

            channel.basicPublish("",QUEUE_NAME,null,message.getBytes());
            System.out.println("消息发送完毕");
        }
    }
}
